const {src,series,dest,parallel,watch}=require("gulp")
const thml = require("gulp-htmlmin")
const css = require("gulp-clean-css")
const js = require("gulp-uglify")
const bable = require("gulp-babel")
const img = require("gulp-imagemin")
const webserver = require("gulp-webserver")
function Html(cb){
    src('./*.html')
    .pipe(thml({
        collapseWhitespace:true
    }))
    .pipe(dest("./dist"))
    cb()
}
function Css(cb){
    src('./css/*.css')
    .pipe(css())
    .pipe(dest("./dist/css"))
    cb()
}
function Js(cb){
    src('./js/*.js')
    .pipe(bable({
        presets:["es2015"]
    }))
    .pipe(js())
    .pipe(dest("./dist/js"))
    cb()
}
function Tu(cb){
    src("./favicon.ico")
    .pipe(dest("./dist"))
    cb()
}
function Img(cb){
    src(["./imgs/*.png","./imgs/*.jpg"])
    .pipe(img())
    .pipe(dest("./dist/imgs"))
    cb()
}
function createServer(cb){
    setTimeout(function(){
        src("./dist")
        .pipe(webserver({
            livereload: true,
            fallback: 'home.html',
            open:true,
        }))
        watch("./*html",Html)
        watch("./css/*.css",Css)
        watch("./js/*.js",Js)
        watch(["./imgs/*.png","./imgs/*.jpg"],Img)
    },2000)
    cb()
}
exports.default = series(parallel(Html,Css,Js,Tu,Img),createServer)